# !/usr/bin/env python
# coding=utf-8
# @Time    : 2018/7/18 13:28
# @Author  : 6imensiva
# @Site    : https://gitee.com/dimensiva/rpc_dao.git
# @File    : open_order.py
# @Software: PyCharm
# @Version: 2.7.5
from idl_output.ttypes import OpenOrderKernel, OpenInsuranceKernel, ReceiverInfo
from db import open_order
from utils import my_decorator


@my_decorator.handle_exception()
def save_open_order(order, insurance, receiver):
	thrift_order = OpenOrderKernel(order)
	thrift_insurance = OpenInsuranceKernel(insurance)
	thrift_receiver = ReceiverInfo(receiver)
	order_id = open_order.save_open_order_kernel(thrift_order.biPremium, thrift_order.ciPremium,
	                                             thrift_order.carshipTax, thrift_order.totalCost,
	                                             thrift_order.orderTime, thrift_order.biProposalNo,
	                                             thrift_order.ciProposalNo, thrift_order.serviceNo,
	                                             thrift_order.status, thrift_order.payState,
	                                             thrift_order.appId, thrift_order.payAmount,
	                                             thrift_order.rebates, thrift_order.msg,
	                                             thrift_order.commissionStatus)

	open_order.save_open_insurance_kernel(thrift_insurance.ciStartDate, thrift_insurance.biStartDate,
	                                      thrift_insurance.biPolicyNo, thrift_insurance.ciPolicyNo,
	                                      thrift_insurance.insureCode, thrift_insurance.insureCity,
	                                      thrift_insurance.ownerName, thrift_insurance.ownerId,
	                                      thrift_insurance.ownerMobile, thrift_insurance.vinNo,
	                                      thrift_insurance.engineNo, thrift_insurance.model,
	                                      thrift_insurance.licenseNo, thrift_insurance.registerDate,
	                                      thrift_insurance.isTrans, thrift_insurance.trans,
	                                      thrift_insurance.content, thrift_insurance.insuredInfo,
	                                      thrift_insurance.policyholder, thrift_receiver.AddresseeName,
	                                      thrift_receiver.AddresseeMobile, thrift_receiver.AddresseeProvince,
	                                      thrift_receiver.AddresseeCity, thrift_receiver.AddresseeCounty,
	                                      thrift_receiver.AddresseeDetails, order_id)